package ar.edu.utn.frsf.tpae.a2013.g04.persistence.dao.impl;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import ar.edu.utn.frsf.tpae.a2013.g04.persistence.dao.UsuarioDAO;
import ar.edu.utn.frsf.tpae.a2013.g04.persistence.model.Usuario;

@Component
public class UsuarioDAOHibernate implements UsuarioDAO {

	private SessionFactory  sessionFactory;
	
	  
	@Override
	public Usuario buscarPorNickname(String nickname) {
		Session session = sessionFactory.getCurrentSession();
	    Query query = session.createQuery("select u from " + " Usuario u"
	        + " where nickname = :nickname");
	    query.setString("nickname", nickname);
	    return (Usuario) query.uniqueResult();
	}


	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

    @Autowired(required=true)
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

}
